IF OBJECT_ID (N'dbo.SectionGetViewOrdinal', N'FN') IS NOT NULL
    DROP FUNCTION dbo.SectionGetViewOrdinal;
GO

Create Function dbo.SectionGetViewOrdinal ( @ChapterID Integer)
Returns  Int
As
Begin
Declare @Ordinal Int
 Select Top(1) @Ordinal= ViewOrder From ChapterSection Where ChapterID = @ChapterID Order By ViewOrder Desc
Set @Ordinal = @Ordinal+1
Return @Ordinal
END
GO


 

 